package com.HomeWorkhsp.Chapter08.encap;

/**
 * Enjoy programming!!!
 * Time: 2021/11/17 -  20:42
 */
public class AccountHW00 {
    private String name;
    private double balance;
    private String password;

    public AccountHW00() {}//无参构造器



    public AccountHW00(String name, double balance, String password) {
        setName(name);
        setBalance(balance);
        setPassword(password);

    }

  public void setName(String name){
        if (name.length() <= 4 && name.length() >= 2)
        this.name = name;
        else{
            System.out.println("长度不对！！(2-4)");
            this.name  = "默认";
        }
    }

    public void setBalance(double balance){
        if (balance > 20.0)
            this.balance = balance;
        else {
            System.out.println("余额输入错误!!");
            this.balance = 0.0;
        }
    }

    public void setPassword(String password){
        if(password.length() == 6)
            this.password = password;
        else{
            System.out.println("密码长度错误，必须是六位!!");
            this.password = "000000";
        }
    }
//    public String getName() {
//        return name;
//    }
//
//    public double getBalance() {
//        return balance;
//    }
//
//    public String getPassword() {
//        return password;
//    }

    public void showInfo(String p){
        if (p == password){
            System.out.println("账户信息：name=" + name + " 余额=" + balance + " 密码=" + password);
        }
        else{
            System.out.println(name + "您的密码错误！！请再试一次");
        }
    }
}

